<?php

namespace app\admin\model\cabinet;

use think\Model;

class Info extends Model
{
    // 表名
    protected $name = 'cabinet_info';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    // 追加属性
    protected $append = [
        'status_text',
        'running_status_text'
    ];
    

    
    public function getStatusList()
    {
        return ['0' => __('Status 0'),'1' => __('Status 1'),'2' => __('Status 2'),'-1' => __('Status -1'),'-2' => __('Status -2')];
    }     

    public function getRunningStatusList()
    {
        return ['0' => __('Running_status 0'),'1' => __('Running_status 1'),'-1' => __('Running_status -1')];
    }     


    public function getStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getRunningStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : (isset($data['running_status']) ? $data['running_status'] : '');
        $list = $this->getRunningStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function type()
    {
        return $this->belongsTo('Type', 'cabinet_type_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function place()
    {
        return $this->belongsTo('app\admin\model\charge\Place', 'charge_place_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
